-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce cron_shutdown function for stopping the main background worker #381
base: main
Are you sure you want to change the base?
Conversation
Normally the main background worker ued to start tasks cannot be stopped, because it always auto restarts. This SQL function can be used to stop the background worker.
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle this makes sense, but would be good if there's also a corresponding start-up function.
@@ -1 +1,7 @@ | |||
/* no SQL changes in 1.6 */ | |||
DROP FUNCTION IF EXISTS cron.shutdown(); | |||
CREATE FUNCTION cron.shutdown() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would require a new SQL script (1.7), otherwise existing 1.6 users will never get the function.
LANGUAGE C STRICT | ||
AS 'MODULE_PATHNAME', $$cron_shutdown$$; | ||
COMMENT ON FUNCTION cron.shutdown() | ||
IS 'shutdown pg_cron'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also revoke execute from public, to ensure only superuser can call this (or grant privileges)
|
||
LWLockAcquire(scheduler_shared_data->lock, LW_EXCLUSIVE); | ||
pid = scheduler_shared_data->scheduler_pid; | ||
scheduler_shared_data->scheduler_pid = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code style should be adapted to the rest of the project
(except the Vixie cron logic in entry.c/misc.c)
Normally the main background worker used to start tasks cannot be stopped, because it always auto restarts.
This change introduces SQL function
cron_shutdown
that can be used to stop the background worker.It works by creating a shared memory that holds pid of the main background worker and bool flag specifying whether to restart the worker. By default, this keeps the current behaviour of automatically restarting the worker whenever it's killed. In situations when the user actually wants the main worker to be killed, It gives a way to do it.
This currently doesn't stop any other worker started by the scheduler.
The change that introduced auto-restarts is #286
Fixes #352